package tests.pl.shenlon.ga;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

import pl.shenlon.ga.BehaviourPattern;
import pl.shenlon.ga.SimpleChromosome;
import pl.shenlon.ga.SimpleSpecimen;
import pl.shenlon.ga.Specimen;
import pl.shenlon.ga.StatefulSpecimen;
import pl.shenlon.poker.game.GameState;

public class SimpleSpecimenTest {
	private SimpleSpecimen specimen;

	@Before
	public void setUp() {
		specimen = new SimpleSpecimen();
	}

	@Test
	public void testConstructors() {
		specimen = new SimpleSpecimen();
		BehaviourPattern pattern = specimen.getGenom().getBehaviourPattern(
				GameState.ANY);
		int sum = 0;
		for (int weight : pattern.getPattern()) {
			sum += weight;
		}
		Assert.assertFalse(sum == 0);

		SimpleSpecimen copy = new SimpleSpecimen(specimen);
		Assert.assertNotSame(specimen, copy);
		Assert.assertNotSame(specimen.getGenom(), copy.getGenom());
		Assert.assertEquals(specimen, copy);
		copy.getGenom().getBehaviourPattern(GameState.ANY)
				.setBluffChance(10000);
		Assert.assertFalse(specimen.equals(copy));

		copy = new SimpleSpecimen((SimpleChromosome) specimen.getGenom());
		Assert.assertNotSame(specimen, copy);
		Assert.assertNotSame(specimen.getGenom(), copy.getGenom());
		Assert.assertEquals(specimen, copy);
		copy.getGenom().getBehaviourPattern(GameState.ANY)
				.setBluffChance(10000);
		Assert.assertFalse(specimen.equals(copy));
	}

	@Test
	public void testCopy() {
		SimpleSpecimen copy = (SimpleSpecimen) specimen.copy();
		Assert.assertNotSame(specimen, copy);
		Assert.assertEquals(specimen, copy);
	}

	@Test(expected = IllegalArgumentException.class)
	public void testCrossover() {
		Specimen parentB = new StatefulSpecimen();
		specimen.crossover(0.0, parentB);
	}
}
